//
//  LLMainTabBarController.swift
//  xinlangweibo
//
//  Created by 任玉林 on 16/6/23.
//  Copyright © 2016年 任玉林. All rights reserved.
//

import UIKit

class LLMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        
        let tabBar = LLTabBar()
        
        tabBar.LLDelegate = self
        
        setValue(tabBar, forKey: "tabBar")

        super.viewDidLoad()
        
        addChildViewController(LLHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        
        addChildViewController(LLMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")

        addChildViewController(LLDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        
        addChildViewController(LLProfileTableViewController(), title: "我的", imageName: "tabbar_profile")
    }
    
    func addChildViewController(vc: UIViewController,title:String,imageName:String) {
        
        vc.title = title
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
        vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")
        
//        vc.tabBarItem.title = title 和 vc.title = title达到同样的效果
        
        let naVC = UINavigationController(rootViewController: vc)
        
        addChildViewController(naVC)
    }
    
}

//实现代理方法
extension LLMainTabBarController: LLTabBarDelegate{
    
    func composeButtonClick() {
        
        
    let naVC = UINavigationController(rootViewController: LLComposeViewController())
        
        presentViewController(naVC, animated: false, completion: nil)
    }
    
    
}
